package com.example.erp.config;

import java.util.function.Function;

import org.springframework.ai.tool.ToolCallbackProvider;
import org.springframework.ai.tool.function.FunctionToolCallback;
import org.springframework.ai.tool.method.MethodToolCallbackProvider;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.example.erp.service.MathService;
import com.example.erp.service.WeatherService;

/**
 * 工具声明与注册
 */
@Configuration
public class ToolCallbackProviderRegister {

	@Bean
	ToolCallbackProvider mathTools(MathService mathService) {
		return MethodToolCallbackProvider.builder().toolObjects(mathService).build();
	}

	@Bean
	ToolCallbackProvider weatherTools(WeatherService weatherService) {
		return MethodToolCallbackProvider.builder().toolObjects(weatherService).build();
	}

	@Bean
	ToolCallbackProvider toUpperCaseTools() {
		return ToolCallbackProvider.from(FunctionToolCallback
				.builder("toUpperCase", (Function<ToUpperCaseInput, String>) input -> input.input().toUpperCase())
				.description("convert string to uppercase").inputType(ToUpperCaseInput.class).build());
	}

	public record ToUpperCaseInput(String input) {
	}

}
